#include <iostream>
#include <vector>
using namespace std;

// 定义三元组结构体
struct Triple {
    int row;
    int col;
    int value;
};

// 稀疏矩阵加法函数
vector<Triple> addSparseMatrices(int rows, int cols, const vector<Triple>& A, const vector<Triple>& B) {
    vector<Triple> result;
    int i = 0, j = 0;
    
    while (i < A.size() && j < B.size()) {
        if (A[i].row < B[j].row || (A[i].row == B[j].row && A[i].col < B[j].col)) {
            result.push_back(A[i]);
            i++;
        } else if (A[i].row > B[j].row || (A[i].row == B[j].row && A[i].col > B[j].col)) {
            result.push_back(B[j]);
            j++;
        } else { // A[i] 和 B[j] 是相同的元素
            Triple sum = {A[i].row, A[i].col, A[i].value + B[j].value};
            if (sum.value != 0) {
                result.push_back(sum);
            }
            i++;
            j++;
        }
    }
    
    // 添加剩余的元素
    while (i < A.size()) {
        result.push_back(A[i]);
        i++;
    }
    while (j < B.size()) {
        result.push_back(B[j]);
        j++;
    }
    
    return result;
}

int main() {
    int rows, cols;
    cin >> rows >> cols;
    
    int numNonZeroA, numNonZeroB;
    cin >> numNonZeroA >> numNonZeroB;
    
    vector<Triple> A(numNonZeroA);
    for (int i = 0; i < numNonZeroA; ++i) {
        cin >> A[i].row >> A[i].col >> A[i].value;
    }
    
    vector<Triple> B(numNonZeroB);
    for (int i = 0; i < numNonZeroB; ++i) {
        cin >> B[i].row >> B[i].col >> B[i].value;
    }
    
    vector<Triple> result = addSparseMatrices(rows, cols, A, B);
    
    // 输出结果矩阵
    vector<vector<int>> outputMatrix(rows, vector<int>(cols, 0));
    for (const auto& triple : result) {
        outputMatrix[triple.row - 1][triple.col - 1] = triple.value;
    }
    
    for (int r = 0; r < rows; ++r) {
        for (int c = 0; c < cols; ++c) {
            cout << outputMatrix[r][c];
            if (c < cols - 1) {
                cout << " ";
            }
        }
        // 去掉每行末尾的换行符
        if (r < rows - 1) {
            cout << endl;
        }
    }
    
    return 0;
}